/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/* Copyright (C) 2012 Zongyou Yao. All rights reserved.     */

#ifndef TEXT_INCLUDED
#define TEXT_INCLUDED

#include <stdarg.h>
#include "fmt.h"

typedef struct text_t {
    int len;
    const char *str;
} text_t;

typedef struct text_save_t *text_save_t;

extern const text_t text_cset;
extern const text_t text_ascii;
extern const text_t text_ucase;
extern const text_t text_lcase;
extern const text_t text_digits;
extern const text_t text_null;

text_t text_put(const char *str);
char * text_get(char *str, int size, text_t s);
text_t text_box(const char *str, int len);
text_t text_sub(text_t s, int i, int j);
int text_pos(text_t s, int i);
text_t text_cat(text_t s1, text_t s2);
text_t text_dup(text_t s, int n);
text_t text_reverse(text_t s);
text_t text_map(text_t s, const text_t *from , const text_t *to);
int text_cmp(text_t s1, text_t s2);
int text_chr(text_t s, int i, int j, int c);
int text_rchr(text_t s, int i, int j, int c);
int text_upto(text_t s, int i, int j, text_t set);
int text_rupto(text_t s, int i, int j, text_t set);
int text_any(text_t s, int i, text_t set);
int text_many(text_t s, int i, int j, text_t set);
int text_rmany(text_t s, int i, int j, text_t set);
int text_find(text_t s, int i, int j, text_t str);
int text_rfind(text_t s, int i, int j, text_t str);
int text_match(text_t s, int i, int j, text_t str);
int text_rmatch(text_t s, int i, int j, text_t str);
void text_fmt(int code, va_list_box *box, int put(int c, void *cl), void *cl, unsigned char flags[], int width, int precision);
text_save_t text_save(void);
void text_restore(text_save_t *save);

#endif
